<?php
/**
 * Created by PhpStorm.
 * User: hoter
 * Date: 2016/9/2
 * Time: 22:48
 */

namespace app\core\components;


use yii\base\Component;

class Config extends Component
{

    public $cacheKey = "allSystemConfigs";

    public function get($key){
//        $configs = \Yii::$app->cache->get($this->cacheKey);
//        if ($configs === false) {
//            $configs = \app\models\Config::find()->asArray()->all();
//            \Yii::$app->cache->set($this->cacheKey, $configs, 60*60);
//        }
        $configs = \app\models\Config::find()->asArray()->all();

        return self::_parse($configs)[$key];
    }

    private static function _parse($configs){
        $result = [];
        foreach ($configs as $config) {//$config = [ 'key'=>sys_icp, 'val'=>ICP]
            $result[$config['key']] = $config['val'];
        }
       return $result;
    }
}